import { GStatic } from "../../../Core/Manager/DataPool";
import GameMgr from "../../Logic/GameMgr";

const { ccclass } = cc._decorator;
@ccclass
export class SOnLineAwardData extends GStatic {
    public parse(obj: any): boolean {
        for (let i = 0; i < obj.data.length; i++) {
            let raw = GStatic.addonRaw<SOnLineAwardDataRaw>(obj.data[i]);
            this._data.set(raw.id, raw);
        }
        return true;
    }

    /**是否领取在线时长奖励 */
    public isReceiveReward(time: number): ONLINEREWARD {
        let bool = false;
        let ONLINEREWARD: ONLINEREWARD = {
            bool: bool,
            reward: [],
            index: 1,
        }
        this.data.forEach((v: SOnLineAwardDataRaw) => {
            if (bool) {
                return;
            }
            let num = GameMgr.lUserData.getOnLineRewardNum();
            if (num < this.data.size) {
                if (time >= v.time && num < v.id) {
                    bool = true;
                    ONLINEREWARD.bool = bool;
                    ONLINEREWARD.reward = v.award;
                } else {
                    ONLINEREWARD.index = num + 1;
                }
            }
        })
        return ONLINEREWARD;
    }

    public isAllReward(v) {
        if (v >= this.data.values.length) {
            return true;
        } else {
            return false;
        }

    }

    public get maxTimeId() {
        let id = 1;
        this._data.forEach((v: SOnLineAwardDataRaw) => {
            id = v.id;
        })
        return id;
    }
}